package com.shiguiwu.springboot3.config;


import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @description: 聊天配置
 * @author: stone
 * @date: Created by 2025/6/19 17:16
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.langchain.config
 */

@Configuration
public class ChatConfig {

    @Autowired
    private ChatMemoryStore redisChatMemoryStore;





    public ChatMemory chatMemory(Object memoryId, ChatMemoryStore redisChatMemoryStore) {
        return MessageWindowChatMemory.builder()
                .maxMessages(20)//最大保存的会话记录数量
                .id(memoryId)
                .chatMemoryStore(redisChatMemoryStore)
                .build();
    }

    @Bean
    public  ChatMemoryProvider chatRedisMemoryProvider() {
        return (memoryId) -> this.chatMemory(memoryId, redisChatMemoryStore);
    }








}